

ROUND2 equ 10

flat_line2:
      mov        edx,1000
      movd       xmm5,edx   ; for rem inside faces proc ..
      pshuflw    xmm5,xmm5,11111000b
flat_line:
;----------------------------------------------------
;-------------in xmm0 - lo -> hi z1, z2
;--------------- eax - x1 ---------------------------
;--------------- ebx - x2 ---------------------------
;--------------- ecx - y-----------------------------
;--------------- edx - x_res ------------------------
;--------------- esi - pointer to z-buffer ----------
;--------------- edi - screen buf
;--------------- xmm7 - col -------------------------
;                xmm5 - ymax, ymin as words ---------


.x_res  equ [ebp-4]
.x1     equ dword[ebp-8]
.x2     equ dword[ebp-12]
.z2     equ [ebp-16]
.z1     equ [ebp-20]
.ymin   equ [ebp-22]
.ymax   equ [ebp-24]

     push       ebp
     mov        ebp,esp
     movzx      edx,dx
     push       edx
     sub        esp,24
     movd       .ymax,xmm5
     cmp        cx,.ymax
     jge        .l_quit

     cmp        cx,.ymin
     jl         .l_quit

     movzx      ecx,cx
     cmp        eax,ebx
     je         .l_quit
     jl         .l_ok

     xchg       eax,ebx
     shufps     xmm0,xmm0,11100001b
   .l_ok:
     mov        .x1,eax
     mov        .x2,ebx

     cmp        eax,edx
     jge        .l_quit
     or         ebx,ebx
     jle        .l_quit

     movlps     .z1,xmm0
     sub        ebx,eax
     movss      xmm6,.z2
     cvtsi2ss   xmm1,ebx
     rcpss      xmm1,xmm1
     subss      xmm6,xmm0  ;.z1
     mulss      xmm6,xmm1

     or         eax,eax    ; eax,0   ; clipping
     jge        @f
     mov        eax,.x1
     neg        eax
     cvtsi2ss   xmm2,eax
     mulss      xmm2,xmm6 ;.dz
     addss      xmm2,xmm0 ;.z1
     movss      .z1,xmm2
     and        .x1,0
    @@:

     cmp        .x2,edx
     jl         @f
     mov       .x2,edx
    @@:
     mov        eax,ecx
     mul        edx
     add        eax,.x1
     shl        eax,2
     add        esi,eax
     add        edi,eax

     mov        ecx,.x2
     sub        ecx,.x1
     movss      xmm2,.z1   ; cz
     mov        ebx,4
     movd       eax,xmm7
   .ccalc:
  ;   movss     xmm1,xmm2
  ;   cmpltss   xmm1,dword[esi]
  ;   movd      edx,xmm1
  ;   or        edx,edx
  ;   jz        @f
     comiss    xmm2,[esi]
     ja        @f
     mov       [edi],eax
     movss     dword[esi],xmm2
    @@:
     add       esi,ebx
     add       edi,ebx
     addps     xmm2,xmm6
     loop      .ccalc


  .l_quit:
     mov       esp,ebp
     pop       ebp
ret

